package com.wenjiang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wenjiang.common.lang.Result;
import com.wenjiang.common.vo.DashboardVo;
import com.wenjiang.common.vo.GoodTypeInfo;
import com.wenjiang.common.vo.MonthPayCount;
import com.wenjiang.entity.MallOrder;
import com.wenjiang.mapper.MallGoodMapper;
import com.wenjiang.mapper.MallGoodTypeMapper;
import com.wenjiang.mapper.MallOrderMapper;
import com.wenjiang.mapper.MallUserMapper;
import com.wenjiang.service.DashboardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DashboardServiceImpl implements DashboardService {



    @Autowired
    MallGoodMapper mallGoodMapper;

    @Autowired
    MallOrderMapper mallOrderMapper;

    @Autowired
    MallUserMapper mallUserMapper;

    @Autowired
    MallGoodTypeMapper mallGoodTypeMapper;


    @Override
    public Result baseInfo() {

        DashboardVo dashboardVo = new DashboardVo();

        //查询总数
        Integer goodCount = mallGoodMapper.selectCount(null);
        // 交易成功的订单数
        Integer orderCount = mallOrderMapper.selectCount(new QueryWrapper<MallOrder>().eq("status", 1));
        Integer userCount = mallUserMapper.selectCount(null);
        int allPayMoney = mallOrderMapper.allPayMoney();

        dashboardVo.setUserCount(userCount);
        dashboardVo.setGoodCount(goodCount);
        dashboardVo.setOrderCount(orderCount);
        dashboardVo.setAllTotal(allPayMoney);

        return Result.succ(dashboardVo);
    }


    @Override
    public Result getNearMonthPayCount() {

        List<MonthPayCount> nearMonthPayCount = mallOrderMapper.getNearMonthPayCount();

        return Result.succ(nearMonthPayCount);
    }

   // 获取各个商品分类的分布个数 （加售卖情况）
    @Override
    public Result getGoodTypeInfo() {

        // 查找各个商品分类的 售卖的分布情况
        List<GoodTypeInfo> typeInfo = mallGoodTypeMapper.getAllGoodTypeInfo();

        return  Result.succ(typeInfo);
    }
}
